package com.se.frontline.gameplay.heroes;

import org.andengine.entity.modifier.MoveModifier;
import org.andengine.entity.modifier.MoveXModifier;
import org.andengine.entity.modifier.MoveYModifier;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.entity.text.Text;

import com.se.frontline.MainActivity;
import com.se.frontline.layers.menu.FinishedMenuLayer;
import com.se.frontline.layers.menu.MainMenuLayer;
import com.se.frontline.managers.ResourceManager;

public class Hero1 extends Hero {

	private static final float MAX_HERO_SPEED = 0.5f;
	private AnimatedSprite mHero1Sprite;
	private MoveXModifier xMovement;
	private MoveYModifier yMovement;
	public float Height;
	public float Width;

	// ====================================================
	// Statistics of this Unit
	// ====================================================

	private int Health;
	private int Damage;
	private int Armor;
	private String state = "LIVE";

	public Hero1(boolean isEnemy) {

		mHero1Sprite = new AnimatedSprite(0, 0,
				ResourceManager.getInstance().mHero1TextureRegion,
				ResourceManager.getInstance().engine
						.getVertexBufferObjectManager());
		/*
		 * long FrameDuration[] = { 100,200,300,400,500,600,700,800,900,1000,
		 * 1100,1200,1300,1400,1500,1600,1700,1800,1900,2000,
		 * 2100,2200,2300,2400,2500,2600,2700,2800,2900,3000,
		 * 3100,3200,3300,3400,3500,3600,3700,3800,3900,4000,
		 * 4100,4200,4300,4400,4500,4600,4700,4800,4900,5000,
		 * 5100,5200,5300,5400,5500,5600,5700,5800,5900,6000,
		 * 6100,6200,6300,6400,6500,6600,6700,6800,6900,7000,
		 * 7100,7200,7300,7400,7500,7600,7700,7800,7900,8000,
		 * 8100,8200,8300,8400,8500,8600,8700,8800,8900,9000, 910 };
		 */
		// mHero1Sprite.animate(300);
		// mHero1Sprite.animate(new long[] { 200, 200, 200, 200}, 0, 3, true);
		this.Height = mHero1Sprite.getHeight();
		this.Width = mHero1Sprite.getWidth();
		ResourceManager.getInstance().getGameGround().attachChild(mHero1Sprite);
		xMovement = new MoveXModifier(MAX_HERO_SPEED, 0, 0);
		yMovement = new MoveYModifier(MAX_HERO_SPEED, 0, 0);
		mHero1Sprite.registerEntityModifier(xMovement);
		mHero1Sprite.registerEntityModifier(yMovement);

		if (state == "LIVE") {
			mHero1Sprite.animate(new long[] { 200, 200, 200, 200 }, 0, 3, true);
		} else if (state == "JUMP") {
			mHero1Sprite.animate(new long[] { 200, 200, 200, 200 }, 4, 7, true);
		} else if (state == "DIE") {
			mHero1Sprite.animate(new long[] { 200, 200 }, 8, 9, true);
		}

	}

	@Override
	public void move(float x, float y, Hero pHero) {
		if (x != 0) {
			// xMovement.reset(MAX_HERO_SPEED, mHero1Sprite.getX(),
			// mHero1Sprite.getX()+x*100);
			mHero1Sprite.setPosition(mHero1Sprite.getX() + x * 10,
					mHero1Sprite.getY());
			if (mHero1Sprite.getX() > 1600) {
				FinishedMenuLayer.getInstance().FadeIn();
				mHero1Sprite.setPosition(1, 10);
			}

		} else {
			// xMovement.reset(MAX_HERO_SPEED, mHero1Sprite.getX(),
			// mHero1Sprite.getX());
			// mHero1Sprite.animate(new long[] { 1, 1}, 8, 9, true);
		}

		if (y != 0) {
			// yMovement.reset(MAX_HERO_SPEED, mHero1Sprite.getY(),
			// mHero1Sprite.getY()+y*100);
			mHero1Sprite.setPosition(mHero1Sprite.getX(), mHero1Sprite.getY()
					+ y * 3);
			this.SetAnimationState("WALK");
		} else {
			this.SetAnimationState("STAND");
			// yMovement.reset(MAX_HERO_SPEED, mHero1Sprite.getY(),
			// mHero1Sprite.getY());
		}
		mHero1Sprite.setUserData(pHero);

	}
	
	@Override
	public void fight(float pDuration, float pPower) {
		if(pDuration==1)
			this.SetAnimationState("FIGHT");
		Thread timer = new Thread() {
			public void run() {
				

					try {
						sleep(500);
					} catch (InterruptedException e) {
						e.printStackTrace();
					} finally {
						state="NULL";
						//System.out.println("3333");

					}
					
			}
		};

		timer.start();
		this.SetAnimationState("STAND");}

	@Override
	public void SetAnimationState(String state2) {
		if(state != "FIGHT"){
			if (state2 == "WALK" && state != state2) {
			state = state2;
			mHero1Sprite.animate(new long[] { 500/8, 500/8, 500/8, 500/8, 500/8, 500/8, 500/8, 500/8, 500/8}, 0, 8, true);
		}
		if (state2 == "DIE" && state != state2) {
			state = state2;
			mHero1Sprite.animate(new long[] { 500/8, 500/8, 500/8, 500/8, 500/8, 500/8, 500/8, 500/8  }, 17, 24, true);
		}
		if (state2 == "FIGHT" && state != state2) {
			state = state2;
			mHero1Sprite.animate(new long[] { 500/8, 500/8, 500/8, 500/8, 500/8, 500/8, 500/8, 500/8  }, 9, 16, true);
		}
		if (state2 == "STAND" && state != state2) {
			state = state2;
			mHero1Sprite.animate(new long[] { 500, 500 }, 7, 8, true);
		}
		}
		}
}